package com.example.javaspringweb.service;

import com.example.javaspringweb.dao.UserMapper;
import com.example.javaspringweb.entity.UserDemo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("UserService")
public class UserServiceImpl implements UserService{

    //    @Autowired是按类型查找Bean，@Resource是按名查找
    @Resource
    private UserMapper usermapper;

    @Override
    @Transactional(readOnly=true)
    public UserDemo userLogin(String username, String password) {
        return usermapper.LoginNameAndPassword(username, password);  //调用DB层方法
    }


    @Override
    @Transactional(readOnly=true)
    public List<UserDemo> findAllUser() {
        return usermapper.FindAllUser();
    }


    @Override
    @Transactional
    public List<UserDemo> addUser(String username, String password) {
        return usermapper.AddUser(username, password);
    }

}

